<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="com.oreilly.servlet.MultipartRequest,com.oreilly.servlet.multipart.DefaultFileRenamePolicy,java.util.*,java.io.*" %>
<%@ page import="java.sql.*,anbook.dto.*" %>
<jsp:useBean id="memberController" class="anbook.dao.controller.MemberController" scope="session" />
<%
if (session.getAttribute("email") == null){
	response.sendRedirect("/BookProject/");
	return;
}

String email = session.getAttribute("email").toString();
Member member = memberController.getMember(email);

request.setCharacterEncoding("UTF-8");
int maxSize = 1024*1024*5;
String encType = "UTF-8";
String savefile = "/myPage/profileImage/images";
ServletContext scontext = getServletContext();
String realFolder = scontext.getRealPath(savefile);

try{
	MultipartRequest multi=new MultipartRequest(request, realFolder, maxSize, encType, new DefaultFileRenamePolicy());
	File file = multi.getFile("image_file");
	if (file != null){
		String realName = email.replace("@", "_") + ".png";
		String realPath = realFolder + "/" + realName;
		File reFile = new File(realPath);
		if (reFile.exists()) reFile.delete();
		file.renameTo(reFile);
		member.setMb_profile(realName);
		memberController.updateMember(member);
	}
	//파일이름 100글자 넘어가면 이상생길 수 있음. 컬럼 한도가 100글자라서,
	//수정방안 생각해볼것.
	
} catch(Exception e) {
	e.printStackTrace();
}

response.sendRedirect("/BookProject/myPage/");
%>